<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty indent t plugin
 *
 * Type:     modifier<br>
 * Name:     t<br>
 * Purpose:  translate text
 * @author   Dzung DH
 * @param string
 * @return string
 */
function smarty_modifier_countdown(){
  $args = func_get_args(); 
  $timestamp = array_shift($args);
  $format = array_shift($args);
  
  if ($timestamp<time()) return "Hết hạn";
  
  $timeDif = $timestamp-time();
  $text = floor($timeDif/86400);
  $unit = 'ngày';
  
  if ($text==0){
    $text = floor($timeDif/3600);
    $unit = 'giờ';
  }
  
  if ($text==0){
    $text = floor($timeDif/60);
    $unit = 'phút';
  }  
  
  if ($text==0) $text = 'Chưa đến '.$text.' '.$unit;
  else $text .= ' ' . $unit;
  
  return $text;
}

?>
